package servlet;

import org.apache.commons.beanutils.BeanUtils;
import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 12-请求参数的封装
 * ②自动封装
 */
@WebServlet("/demo17")
public class Demo17Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = new User();//空User对象
        try {
            BeanUtils.populate(user, request.getParameterMap());//给空User对象的属性赋值
            System.out.println("user = " + user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
